﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.IO;

public partial class DemoCalculator : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            table2.Visible = false;

    }
    protected void GhinhanButton_Click(object sender, EventArgs e)
    {
        //Server.Execute();
        // NameValueCollection queryString = new NameValueCollection();
        int Soluong = Int32.Parse(SoluongTextBox.Text);
        decimal Gia = decimal.Parse(GiaTextBox.Text);
        if (Request.Cookies["Order"] != null)
        {
            Response.Cookies.Add(Request.Cookies["Order"]);
        }
        Response.Cookies["Order"][MaHangTextBox.Text] = MaHangTextBox.Text + " - " + Soluong.ToString() + " - " + Gia.ToString() + " - " + (Soluong * Gia).ToString();

        ShowTextbox.Items.Clear();






        NameValueCollection a = Request.Cookies["Order"].Values;
        foreach (string i in a.Keys)
            ShowTextbox.Items.Add(a[i]);
        // ShowTextbox.Items.Add(MaHangTextBox.Text + " - " + Soluong.ToString() + " - " + Gia.ToString() + " - " + (Soluong * Gia).ToString() + "\n");


        //   Response.Cookies["Order"]["Sp2"] = MaHangTextBox.Text + " - " + Soluong.ToString() + " - " + Gia.ToString() + " - " + (Soluong * Gia).ToString();
        //   ShowTextbox.Items.Add((string)Request.Cookies["Order"]["Sp2"]);

        // ShowTextbox.Items.Add(MaHangTextBox.Text + " - " + Soluong.ToString() + " - " + Gia.ToString() + " - " + (Soluong * Gia).ToString() + "\n");
    }
    protected void TinhButton_Click(object sender, EventArgs e)
    {
        decimal sothu1 = decimal.Parse(Sothu1TextBox.Text);
        decimal sothu2 = decimal.Parse(Sothu2TextBox.Text);
        decimal Ketqua = 0;

        if (RadioButtonList1.SelectedValue == "+")
        {
            Ketqua = sothu1 + sothu2;
            KQTextBox.Text = Ketqua.ToString();
        }
        else if (RadioButtonList1.SelectedValue == "-")
        {
            Ketqua = sothu1 - sothu2;
            KQTextBox.Text = Ketqua.ToString();
        }
        else if (RadioButtonList1.SelectedValue == "*")
        {
            Ketqua = sothu1 * sothu2;
            KQTextBox.Text = Ketqua.ToString();
        }
        else if (RadioButtonList1.SelectedValue == "/")
        {
            Ketqua = sothu1 / sothu2;
            KQTextBox.Text = Ketqua.ToString();
        }
    }
    protected void CopyButton_Click(object sender, EventArgs e)
    {
        tongtienTextBox.Text = KQTextBox.Text.ToString();
        ShowTextbox.Items.Add("Tổng tiền: " + tongtienTextBox.Text);
    }
    protected void VButton_Click(object sender, EventArgs e)
    {
        table2.Visible = !table2.Visible;
    }
}